<#assign baseURL = springMacroRequestContext.getContextPath() />
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>地图配置</title>
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="assets/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="assets/select2%204.0.3/css/select2.min.css" rel="stylesheet">
    <link href="assets/css/plugins/jsTree/style.min.css" rel="stylesheet">
    <link href="assets/css/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet">
    <link href="assets/css/animate.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="assets/ipicture/css/iPicture_location.css" rel="stylesheet">
    <link href="assets/img/log.ico" rel="shortcut icon">
    <style>
        .HKbuttonBlue{
            border:none;
            border-radius: 2px;
            background-color: #3f85e4;
            color:#ffffff;
            width:90px;
            height: 30px;
        }
        .HKbuttonBlue:hover{
            background-color: #3876cb;
        }
        .HKbuttonBlue:active{
            background-color: #2d5fa4;
        }
        .HKbuttonBlue:disabled{
            background-color: #3f85e4;
            opacity: 20;
        }
        .HKbuttonGreen{
            outline: none;
            border:1px solid #45b97c;
            border-radius: 2px;
            background-color: #ffffff;
            color:#45b97c;
            width:90px;
            height: 30px;
        }
        .HKbuttonGreen:hover{
            border-color: #61d845;
        }
        .HKbuttonGreen:active{
            border-color: #1d952f;
        }
        .HKbuttonGreen:disabled{
            border: none;
            opacity: 50;
        }
        .HKbuttonYellow{
            outline: none;
            border:1px solid #dec672;
            border-radius: 2px;
            background-color: #ffffff;
            color:#dec672;
            width:90px;
            height: 30px;
        }
        .HKbuttonYellow:hover{
            border-color: #ffc20e;
        }
        .HKbuttonYellow:active{
            border-color: #fdb933;
        }
        .HKbuttonYellow:disabled{
            border: none;
            opacity: 50;
        }
        .HKbuttonRed{
            outline: none;
            border:1px solid #f391a9;
            border-radius: 2px;
            background-color: #ffffff;
            color:#f391a9;
            width:90px;
            height: 30px;
        }
        .HKbuttonRed:hover{
            border-color: #ef4136;
        }
        .HKbuttonRed:active{
            border-color: #ed1941;
        }
        .HKbuttonRed:disabled{
            border: none;
            opacity: 50;
        }
        .HKbuttonGray{
            outline: none;
            border:1px solid #cccccc;
            border-radius: 2px;
            background-color: #ffffff;
            color:#666666;
            width:90px;
            height: 30px;
        }
        .HKbuttonGray:hover{
            border-color: #3876cb;
            color:#3876cb;
        }
        .HKbuttonGray:active{
            border-color: #2d5fa4;
            color:#2d5fa4;
        }
        .HKbuttonGray:disabled{
            border-color: #eaeaea;
            background-color: #f3f3f3;
            color:#cccccc;
        }

    </style>
</head>
<body>
<div id="wrapper">
    <div class="gray-bg dashbard-1">
        <div class="row wrapper border-bottom white-bg page-heading">
            <div class="col-lg-9">
                <h2>地图配置</h2>
            </div>
        </div>
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="col-lg-3">
                    <div class="row">
                        <div class="panel panel-default">
                            <div class="panel-body">
                                <div id="jsTreeJSON"></div>
                            </div>
                        </div>
                        <input id="jsTreeId"  style="display: none" class="form-control" >
                        <div class="col-xs-12" style="padding-top:10px">
                            <form id="locationSelectForm" class="form-horizontal">
                                <div class="form-group">
                                    <label class="col-lg-3 control-label">标注目标</label>
                                    <div class="col-lg-6"><select id="locationSelect"  class=" form-control " tabindex="-1" aria-hidden="true" style="width: 100%"></select></div>
                                    <div class="col-lg-2 container">
                                        <button id="locationPosBtn" type="button" class="HKbuttonBlue">&nbsp;保存坐标点</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <input id="xInput"  style="display: none" class="form-control" >
                        <input id="yInput"  style="display: none"  class="form-control" >


                    </div>
                </div>
                <div class="col-lg-9">
                    <div class="panel panel-default">
                        <div class="panel-heading" style="padding: 5px 5px 5px 5px" >
                            <div class="row">
                                <div class="col-md-12" style="padding: 0 0 0 0">
                                    <div class="col-md-1" >
                                        <button id="addFloorBtn" type="button" class="HKbuttonBlue" data-toggle="modal" data-target="#floorAddModal" >&nbsp;添加楼层</button>
                                    </div>
                                    <div class="col-md-1" >
                                        <button id="addBuildingBtn" type="button" class="HKbuttonBlue" data-toggle="modal" data-target="#buildingAddModal" >&nbsp;添加建筑</button>
                                    </div>
                                    <div class="col-md-1" >
                                        <button type="button" class="HKbuttonBlue" data-toggle="modal" data-target="#areaAddModal" >&nbsp;添加区域</button>
                                    </div>
                                    <div class="modal inmodal" id="areaAddModal"  role="dialog" aria-hidden="true" >
                                        <div class="modal-dialog">
                                            <div class="modal-content animated bounceInRight">
                                                <div class="modal-header">
                                                    <i class="fa fa-hospital-o modal-icon"></i>
                                                    <h4 class="modal-title">添加区域位置信息</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <form id="areaForm" class="form-horizontal">
                                                        <div class="form-group"><label class="col-lg-2 control-label">区域名称</label>
                                                            <div class="col-lg-10"><input id="areaInput"  class="form-control" name="areaInput" ></div>
                                                        </div>
                                                    </form>
                                                </div>
                                                <div class="modal-footer">
                                                    <button id="areaCANCEL" type="button" class="HKbuttonGray" data-dismiss="modal">&nbsp;&nbsp;取消</button>
                                                    <button id="areaSave" type="button" class="HKbuttonBlue">&nbsp;&nbsp;保存</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="modal inmodal" id="buildingAddModal"  role="dialog" aria-hidden="true" >
                                        <div class="modal-dialog">
                                            <div class="modal-content animated bounceInRight">
                                                <div class="modal-header">
                                                    <i class="fa fa-hospital-o modal-icon"></i>
                                                    <h4 class="modal-title">添加建筑物位置信息</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <form id="buildingForm" class="form-horizontal">
                                                        <div class="form-group"><label class="col-lg-3 control-label">区域名称</label>
                                                            <div class="col-lg-9"><select id="areaSelect"  class=" form-control " tabindex="-1" aria-hidden="true" style="width: 100%"></select></div>
                                                        </div>
                                                        <div class="form-group"><label class="col-lg-3 control-label">建筑物名称</label>
                                                            <div class="col-lg-9"><input id="buildingInput"  class="form-control" name="buildingInput" ></div>
                                                        </div>
                                                    </form>
                                                </div>
                                                <div class="modal-footer">
                                                    <button id="buildingCANCEL" type="button" class="HKbuttonGray" data-dismiss="modal"><i class="fa fa-mail-reply"></i>&nbsp;&nbsp;取消</button>
                                                    <button id="buildingSave" type="button" class="HKbuttonBlue"><i class="fa fa-check"></i>&nbsp;&nbsp;保存</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="modal inmodal" id="floorAddModal"  role="dialog" aria-hidden="true" style="z-index: 2">
                                        <div class="modal-dialog">
                                            <div class="modal-content animated bounceInRight">
                                                <div class="modal-header">
                                                    <i class="fa fa-hospital-o modal-icon"></i>
                                                    <h4 class="modal-title">添加楼层位置信息</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <form id="floorForm" class="form-horizontal">
                                                        <div class="form-group"><label class="col-lg-3 control-label">区域名称</label>
                                                            <div class="col-lg-9"><select id="areaSelect2"  class=" form-control " tabindex="-1" aria-hidden="true" style="width: 100%"></select></div>
                                                        </div>
                                                        <div class="form-group"><label class="col-lg-3 control-label">建筑物名称</label>
                                                            <div class="col-lg-9"><select id="buildingSelect"  class=" form-control " tabindex="-1" aria-hidden="true" style="width: 100%"></select></div>
                                                        </div>
                                                        <div class="form-group"><label class="col-lg-3 control-label">楼层名称</label>
                                                            <div class="col-lg-9"><input id="floorInput"  class="form-control" name="floorInput" ></div>
                                                        </div>
                                                    </form>
                                                </div>
                                                <div class="modal-footer">
                                                    <button id="floorCANCEL" type="button" class="HKbuttonGray" data-dismiss="modal">&nbsp;&nbsp;取消</button>
                                                    <button id="floorSave" type="button" class="HKbuttonBlue">&nbsp;&nbsp;保存</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="modal inmodal" id="mapAddModal"  role="dialog" aria-hidden="true" >
                                        <div class="modal-dialog">
                                            <div class="modal-content animated bounceInRight">
                                                <div class="modal-header">
                                                    <i class="fa fa-hospital-o modal-icon"></i>
                                                    <h4 class="modal-title">添加地图信息</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <form id="mapForm" class="form-horizontal">
                                                        <div style="display: none" class="form-group"><label class="col-lg-3 control-label">位置ID</label>
                                                            <div class="col-lg-9"><input id="mapInput"  class="form-control" name="id" ></div>
                                                        </div>
                                                        <div class="form-group"><label class="col-lg-3 control-label">图片位置</label>
                                                            <div class="col-lg-9"><input id="mapFileInput" type="file" accept="image/jpeg,image/png"  class="form-control" name="file" placeholder="地图位置......"></div>
                                                        </div>
                                                    </form>
                                                </div>
                                                <div class="modal-footer">
                                                    <button id="mapCANCEL" type="button" class="HKbuttonGray" data-dismiss="modal">&nbsp;&nbsp;取消</button>
                                                    <button id="mapSave" type="button" class="HKbuttonBlue">&nbsp;&nbsp;保存</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="modal inmodal" id="changeModal"  role="dialog" aria-hidden="true" >
                                        <div class="modal-dialog">
                                            <div class="modal-content animated bounceInRight">
                                                <div class="modal-header">
                                                    <i class="fa fa-hospital-o modal-icon"></i>
                                                    <h4 class="modal-title">修改位置信息</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <form id="changeForm" class="form-horizontal">
                                                        <div class="form-group"><label class="col-lg-3 control-label">修改名称</label>
                                                            <div class="col-lg-9"><input id="changeInput"  class="form-control" name="changeInput" ></div>
                                                        </div>
                                                    </form>
                                                </div>
                                                <div class="modal-footer">
                                                    <button id="changeCANCEL" type="button" class="HKbuttonGray" data-dismiss="modal">&nbsp;&nbsp;取消</button>
                                                    <button id="changeSave" type="button" class="HKbuttonBlue">&nbsp;&nbsp;保存</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-1" >
                                        <button id="mapBtn" type="button" class="HKbuttonGreen" data-toggle="modal" data-target="#mapAddModal" >&nbsp;&nbsp;添加地图</button>
                                    </div>
                                    <div class="col-md-1" >
                                        <button id="changeBtn" type="button" class="HKbuttonYellow" data-toggle="modal" data-target="#changeModal" >&nbsp;&nbsp;修改数据</button>
                                    </div>
                                    <div class="col-md-1" >
                                        <button id="deleteBtn" type="button" class="HKbuttonRed"></i>&nbsp;&nbsp;删除数据</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div  class="panel-body">
                            <div class="row">
                                <div id="showMap" class="col-md-12">
                                    <div id="iPicture" data-interaction="hover">
                                        <div id="mapPicture" class="ip_slide">
                                            <img id="dtMapImg" src="assets/img/error.jpg" alt="加载地图失败" width="100%" onclick="mapOnClick(event)" />
                                            <div id="pos" class="ip_tooltip ip_img32" style="top: 10px; left: 10px;"  data-round="roundBgR">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
<script src="assets/js/jquery-2.1.1.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="assets/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="assets/js/inspinia.js"></script>
<script src="assets/select2%204.0.3/js/select2.full.min.js"></script>
<script src="assets/js/plugins/pace/pace.min.js"></script>
<script src="assets/js/plugins/jquery-ui/jquery-ui.min.js"></script>
<script src="assets/js/plugins/fullcalendar/moment.min.js"></script>
<script src="assets/js/plugins/jsTree/jstree.min.js"></script>
<script src="assets/ipicture/js/jquery.ipicture_location.js"></script>
<script src="assets/customize.js"></script>

<script>
    $(function(){
        initJstree();

        $("#locationSelect").select2({
            dropdownParent: $('#locationSelectForm'),
            language: {
                "noResults": function () {
                    return "没有数据";
                }
            },
            allowClear:true,
            placeholder: "请选择地理位置",
            data:null
        });
    });

    $("#locationSelect").change(function () {
        var ID = $("#locationSelect").val();
        $.ajax({
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            url: "${baseURL}/json/geo_location/getById?id=" + ID,
            async:false,
            success: function (data) {
                if(data.code === 0){
                    var x_pos = data.data.root.pos_x;
                    var y_pos = data.data.root.pos_y;
                    $("#pos").css({
                        "left":($("#dtMapImg").width()) * x_pos + "px",
                        "top":($("#dtMapImg").height()) * y_pos + "px",
                    });
                }
            }
        });
    })
    function initJstree() {
        $.ajax({
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            // url: "${baseURL}/water/dt_geobuilding/getTree",
            url:"${baseURL}/json/geo_location/getTree",
            async:false,
            success:function (data_in) {
                $('#jsTreeJSON').data('jstree',false).empty();
                $('#jsTreeJSON').jstree({
                    'core' : {
                        'data' : data_in.data,
                        'async' : true
                    }
                });
            }
        });
        $("#changeBtn").prop("disabled", true);
        $("#deleteBtn").prop("disabled", true);
        $("#mapBtn").prop("disabled", true);
        $("#posBtn").prop("disabled", true);
    }

    $("#jsTreeJSON").on("select_node.jstree", function (e, data) {
        $("#changeBtn").prop("disabled", false);
        $("#deleteBtn").prop("disabled", false);
        $("#mapBtn").prop("disabled", false);
        $("#jsTreeId").val(data.node.id);
        // var imgUrl = "http://" + getURL() + "${baseURL}/water/file/dt_geobuilding/getMap?id=" + data.node.id;
        var imgUrl = "${baseURL}/picture/geo_location/download?id=" + data.node.id;
        $("#titleH5").empty();
        // $("#mapPicture").empty();
        // $("#mapPicture").append(
        //     '<img id="mapImg" width="100%"  src='+ imgUrl + ' style="margin:0;padding: 0" onclick="mapOnClick(event)" />'
        // );
        $("#dtMapImg").attr("src", imgUrl);
        var level = data.node.parents.length;
        if(level == 1 || level ==2){
            $("#pos").css("display","block");
            $.ajax({
                type: "GET",
                contentType: "application/json",
                dataType: "json",
                // url: "${baseURL}/water/dt_geobuilding/getBuilding?parent_id=" + data.node.id,
                url: "${baseURL}/json/geo_location/getById?id=" + data.node.id,
                async:false,
                success: function (data) {
                    var localData = [];
                    for(var i in data.data.children){
                        var datas={
                            text : data.data.children[i].name,
                            id:data.data.children[i].id,
                        }
                        localData.push(datas);
                    }
                    if(data.code === 0){
                        $("#locationSelect").find('option').remove();
                        $("#locationSelect").select2({
                            dropdownParent: $('#locationSelectForm'),
                            language: {
                                "noResults": function () {
                                    return "没有数据";
                                }
                            },
                            allowClear:true,
                            q:"name",
                            placeholder: "请选择地理位置",
                            data:localData
                        });
                        $("#dtMapImg").load(function () {
                            if(data.data.children.length != 0)
                            {
                                console.log("非零");
                                var x_pos = data.data.children[0].pos_x;
                                var y_pos = data.data.children[0].pos_y;
                                var name = data.data.children[0].name;
                                $("#pos").css({
                                    "left":($("#dtMapImg").width()) * x_pos + "px",
                                    "top":($("#dtMapImg").height()) * y_pos + "px",
                                });
                                //$("#mapPicture").append('<div id="posimg" class="ip_tooltip ip_img32" style="top:' + (h * y_pos) + "px" + ' ; left:' + (w * x_pos) + "px" + ' ;" data-tooltipbg="bgblack" data-animationtype="btt-slide"  data-round="roundBgW"><p style="text-align: center">'+name+'</p></div>');
                                $("#iPicture").iPicture_base();
                            }

                        });

                    }
                }
            });
        }
        else{
            $("#pos").css("display","none");
            $("#locationSelect").find('option').remove();
            $("#locationSelect").select2({
                dropdownParent: $('#locationSelectForm'),
                language: {
                    "noResults": function () {
                        return "没有数据";
                    }
                },
                allowClear:true,
                placeholder: "请选择地理位置",
                data:null
            });
        }
    });

    $("#areaSave").click(function(){
        var text = $("#areaInput").val();
        if(text != ""){
            $.ajax({
                type: "POST",
                contentType: "application/json",
                dataType: "json",
                // url: "${baseURL}/water/dt_geobuilding/addArea",
                url:"${baseURL}/json/geo_location/add",
                data:JSON.stringify({"name":text,"parent_id":0,"level":1}),
                success:function(data){
                    if(data.code === 0){
                        swal({
                            title: "添加成功。",
                            type: "success"
                        },function(isConfirm){
                            if(isConfirm) location.reload();
                        });
                    }
                    else{
                        swal({
                            title: "数据已存在。",
                            type: "error"
                        })
                    }
                },
                error:function(xhr, status, error){
                    swal({
                        title: "请求失败。",
                        type: "error"
                    })
                }
            });
        }
    });

    $("#deleteBtn").click(function(){
        var id = $("#jsTreeJSON").jstree("get_selected")[0];
        $.ajax({
            type: "POST",
            contentType: "application/json",
            dataType: "json",
            // url: "${baseURL}/water/dt_geobuilding/delete?id=" + id,
            url:"${baseURL}/json/geo_location/delete",
            data:JSON.stringify({"id":id}),
            success:function(data){
                if(data.code === 0){
                    swal({
                        title: "删除成功。",
                        type: "success"
                    },function(isConfirm){
                        if(isConfirm) location.reload();
                    });
                }
                else{
                    swal({
                        title: "删除失败。",
                        type: "error"
                    })
                }
            },
            error:function(xhr, status, error){
                swal({
                    title: "请求失败。",
                    type: "error"
                })
            }
        });
    });

    $("#addBuildingBtn").click(function(){
        $.ajax({
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            // url: "${baseURL}/water/dt_geobuilding/getArea",
            url:"${baseURL}/json/geo_location/getTree",
            async:false,
            success: function (data) {
                console.log(data.data);
                var localData = [];
                for(var i in data.data){
                    var datas={
                        text : data.data[i].text,
                        id:data.data[i].id,
                    }
                    localData.push(datas);
                }
                if(data.code === 0){
                    $("#areaSelect").select2({
                        dropdownParent: $('#buildingForm'),
                        language: {
                            "noResults": function () {
                                return "没有数据";
                            }
                        },
                        allowClear:false,
                        placeholder: "请选择区域",
                        data:localData
                    });
                }
            }
        });
    });

    $("#buildingSave").click(function(){
        var parent_id = $("#areaSelect").find("option:selected").val();
        var text = $("#buildingInput").val();
        if(text != ""){
            $.ajax({
                type: "POST",
                contentType: "application/json",
                dataType: "json",
                // url: "${baseURL}/water/dt_geobuilding/addArea",
                url:"${baseURL}/json/geo_location/add",
                data:JSON.stringify({"name":text,"parent_id":parent_id,"level":2}),
                success:function(data){
                    if(data.code === 0){
                        swal({
                            title: "添加成功。",
                            type: "success"
                        },function(isConfirm){
                            if(isConfirm) location.reload();
                        });
                    }
                    else{
                        swal({
                            title: "数据已存在。",
                            type: "error"
                        })
                    }
                },
                error:function(xhr, status, error){
                    swal({
                        title: "请求失败。",
                        type: "error"
                    })
                }
            });
        }
    });

    $("#addFloorBtn").click(function(){
        $.ajax({
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            // url: "${baseURL}/water/dt_geobuilding/getArea",
            url:"${baseURL}/json/geo_location/getTree",
            async:false,
            success: function (data) {
                var localData = [];
                for(var i in data.data){
                    var datas={
                        text : data.data[i].text,
                        id:data.data[i].id,
                    }
                    localData.push(datas);
                };
                console.log(localData);
                if(data.code === 0){
                    $("#areaSelect2").select2({
                        dropdownParent: $('#floorForm'),
                        language: {
                            "noResults": function () {
                                return "没有数据";
                            }
                        },
                        allowClear:false,
                        placeholder: "请选择区域",
                        data:localData
                    });
                }
            }
        });
        var parent_id = $("#areaSelect2").find("option:selected").val();
        console.log("parent_id:"+parent_id);
        $.ajax({
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            url: "${baseURL}/json/geo_location/getById?id=" + parent_id,
            async:false,
            success: function (data) {
                var localData = [];
                for(var i in data.data.children){
                    var datas={
                        text : data.data.children[i].name,
                        id:data.data.children[i].id,
                    }
                    localData.push(datas);
                }
                if(data.code === 0){
                    $("#buildingSelect").select2({
                        dropdownParent: $('#floorForm'),
                        language: {
                            "noResults": function () {
                                return "没有数据";
                            }
                        },
                        allowClear:false,
                        placeholder: "请选择建筑物",
                        data:localData
                    });
                }
            }
        });
    });

    $("#areaSelect2").on("select2:open change",function(e){
        var parent_id = $("#areaSelect2").find("option:selected").val();
        $("#buildingSelect").empty();
        $.ajax({
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            url: "${baseURL}/json/geo_location/getById?id=" + parent_id,
            async:false,
            success: function (data) {
                var localData = [];
                for(var i in data.data.children){
                    var datas={
                        text : data.data.children[i].name,
                        id:data.data.children[i].id,
                    }
                    localData.push(datas);
                }
                if(data.code === 0){
                    $("#buildingSelect").select2({
                        dropdownParent: $('#floorForm'),
                        language: {
                            "noResults": function () {
                                return "没有数据";
                            }
                        },
                        allowClear:false,
                        placeholder: "请选择建筑物",
                        data:localData
                    });
                }
            }
        });
    });

    $("#floorSave").click(function(){
        var parent_id = $("#buildingSelect").find("option:selected").val();
        var text = $("#floorInput").val();
        if(text != ""){
            $.ajax({
                type: "POST",
                contentType: "application/json",
                dataType: "json",
                // url: "${baseURL}/water/dt_geobuilding/addArea",
                url:"${baseURL}/json/geo_location/add",
                data:JSON.stringify({"name":text,"parent_id":parent_id,"level":3}),
                success:function(data){
                    if(data.code === 0){
                        swal({
                            title: "添加成功。",
                            type: "success"
                        },function(isConfirm){
                            if(isConfirm) location.reload();
                        });
                    }
                    else{
                        swal({
                            title: "数据已存在。",
                            type: "error"
                        })
                    }
                },
                error:function(xhr, status, error){
                    swal({
                        title: "请求失败。",
                        type: "error"
                    })
                }
            });
        }
    });

    $("#mapBtn").click(function(){
        var id = $("#jsTreeJSON").jstree("get_selected")[0];
        $("#mapInput").val(id);
    });

    $("#mapSave").click(function(){
        var form = new FormData(document.forms.namedItem("mapForm"));
        var values = document.getElementById("jsTreeId").value;
        if(values != ""){
            $.ajax({
                url:"${baseURL}/picture/geo_location/upload?id="+values,
                contentType: false,
                cache: false,
                processData: false,
                type: 'POST',
                dataType: 'json',
                data: form,
                success:function(data){
                    if(data.code === 0) {
                        swal({
                            title: "操作成功",
                            type: "success"
                        },function(isConfirm){
                            if(isConfirm) location.reload();
                        });
                    }
                },
                error:function(error) {
                    swal({
                        title: "提交失败，请检查输入的内容。",
                        type: "error"
                    })
                }
            });
        }else {
            swal({
                title: "提交失败，请检查输入的内容。",
                type: "error"
            })
        }

    });

    $("#changeSave").click(function(){
        var id = $("#jsTreeJSON").jstree("get_selected")[0];
        var text = $("#changeInput").val();
        if(text != ""){
            $.ajax({
                type: "POST",
                contentType: "application/json",
                dataType: "json",
                // url: "${baseURL}/water/dt_geobuilding/updateName",
                url:"${baseURL}/json/geo_location/update",
                data:JSON.stringify({"name":text,"id":id}),
                success:function(data){
                    if(data.code === 0){
                        swal({
                            title: "修改成功。",
                            type: "success"
                        },function(isConfirm){
                            if(isConfirm) location.reload();
                        });
                    }
                    else{
                        swal({
                            title: "修改失败。",
                            type: "error"
                        })
                    }
                },
                error:function(xhr, status, error){
                    swal({
                        title: "请求失败。",
                        type: "error"
                    })
                }
            });
        }
    });

    function mapOnClick(e){
        e = e || window.event;
        var imgId ='#'+ $(e.target).attr('id');
        var currentWidth = $(imgId).width();
        var currentHeight = $(imgId).height();
        var offsetX = e.pageX - $(imgId).offset().left;
        var offsetY = e.pageY - $(imgId).offset().top;
        var x = offsetX / currentWidth;
        var y = offsetY / currentHeight;

        $("#xInput").val(x);
        $("#yInput").val(y);
        $("#pos").css({
            "left":($("#dtMapImg").width()) * x + "px",
            "top":($("#dtMapImg").height()) * y + "px",
        });
    };

    $("#locationPosBtn").click(function(){
        var x = $("#xInput").val();
        var y = $("#yInput").val();
        var id =  parseInt($("#locationSelect").find("option:selected").val());
        var datas = {
            id:id,
            pos_x:x,
            pos_y:y
        };
        console.log("datas:"+datas);
        if(x == "" || y == "" ||  id == ""){
            swal({
                title: "请点选坐标和输入数据。",
                type: "error"
            });
        }else{
            $.ajax({
                type: "POST",
                contentType: "application/json",
                dataType: "json",
                async: false,
                // url: "${baseURL}/water/dt_geobuilding/xyUpload",
                url:"${baseURL}/json/geo_location/update_pos",
                data:JSON.stringify(datas),
                success:function(data){
                    if(data.code === 0){
                        swal({
                            title: "修改成功。",
                            type: "success"
                        },function(isConfirm){
                            if(isConfirm) location.reload();
                        });
                    }
                    else{
                        swal({
                            title: "修改失败,地理信息是否异常？",
                            type: "error"
                        })
                    }
                },
                error:function(xhr, status, error){
                    console.log(xhr.responseText)
                    swal({
                        title: "请求失败。",
                        type: "error"
                    })
                }
            });
        }
    });

    $("button.btnFlag").click(function(){
        $("#posPNG").remove();
        console.log("remove")
    });
</script>
</body>
</html>